package com.inspur.edp.common.expr.visitor.construct;

import com.inspur.edp.common.expr.spi.ConstructVisitor;
import com.inspur.edp.common.expr.visitor.VisitResult;
import com.inspur.edp.common.expr.visitor.type.JavaTypeReferConverter;
import com.inspur.edp.common.type.Type;
import com.inspur.edp.common.type.TypeRefer;


import java.util.ArrayList;
import java.util.List;

/**
 * @author lizhaorui
 * @description TODO
 * @date 2024/7/16 16:40
 */
public class JavaDefaultConstructVisitor implements ConstructVisitor {

    public static final String MODE = "default";

    @Override
    public String getType() {
        return MODE;
    }

    @Override
    public VisitResult visit(TypeRefer typeRefer, Type type, String parameters) {
        String javaClassName = JavaTypeReferConverter.getJavaClassName(typeRefer);
        String script = String.format("new %s(%s)", javaClassName, parameters);
        List<String> imports = new ArrayList<>();
        imports.add(type.getTypeOptCode());
        VisitResult result = new VisitResult(script);
        result.setImports(imports);
        return result;
    }
}
